package com.mvd.app.ac2020;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.BottomMenu;
import com.kongzue.dialog.v3.MessageDialog;
import com.kongzue.dialog.v3.WaitDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.activity.BaseActivity;
import com.mvd.app.activity.NewCarDetailsActivity;
import com.mvd.app.adapter.DiaoDuCarsListAdapter;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.Constants;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.NewCarsModel;
import com.mvd.app.model.UserAccountModel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author Administrator
 * @version V1.0
 * @Title: DiaoDuActivity
 * @Package com.mvd.app.ac2020
 * @Description: 调度---上线
 * @date 2020-08-19 9:00
 **/

public class DiaoDuActivity extends BaseActivity {

    @BindView(R.id.ac_diaodu_new_cars)
    ListView acDiaoduNewCars;
    @BindView(R.id.ac_diaodu_cars_fab)
    Button acDiaoduCarsFab;
    @BindView(R.id.ac_diaodu_btn_shangxian)
    Button acDiaoduBtnShangxian;
    @BindView(R.id.ac_car_details_waijianchedao)
    TextView acCarDetailsWaijianchedao;
    @BindView(R.id.ac_diaodu_yincheyuan)
    TextView acDiaoduYincheyuan;
    @BindView(R.id.ac_diaodu_digou_user)
    TextView acDiaoduDigouUser;
    @BindView(R.id.ac_diaodu_fab)
    FloatingActionButton acDiaoduFab;
    private String Login_name = "", login_IDNumber;//当前登录的检测员的名字
    public DiaoDuActivity instances = null;
    //查询出来的列表
    private List<NewCarsModel> carsInforModelList = new ArrayList<NewCarsModel>();
    private DiaoDuCarsListAdapter diaoduAdapter;
    private String zhoushu = "0";//轴数
    private List<NewCarsModel> newCarsModelArrayList_intent = new ArrayList<NewCarsModel>();//传递数据用的
    public List<UserAccountModel> diaoduUserList = new ArrayList<>();
    private List<UserAccountModel> resultList = null;
    private List<UserAccountModel> resultList_digou = null;
    private List<String> resultList_string = new ArrayList<>();
    private List<String> zhoushu_string = new ArrayList<>();
    private List<String> digou_string = new ArrayList<>();
    private List<String> line_str = new ArrayList<>();
    private String yinche_name = "", yinche_ID = "";
    private String digou_name = "", digou_ID = "", line = "1";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_diao_du);
        ButterKnife.bind(this);
        setBackBtn();
        setTopTitle("调度上线");

        instances = this;
        String logStrf = "\n" + "onCreate---DiaoDuActivity--调度---上线-------" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        Login_name = getIntent().getExtras().getString("login_UserID", "");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        yinche_ID = login_IDNumber;
        acDiaoduYincheyuan.setText(Login_name);
        setRightTxt("上线", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //上线
                upLine();
            }
        });

        getCarsList();
        init_data();
//        WaitDialog.show(instances, "加载中...");
        getDataUsersList();
//        WaitDialog.dismiss();
    }

    void init_data() {
        for (int i = 0; i < Constants.ZHOUSHOU_LIST.length; i++) {
            zhoushu_string.add(Constants.ZHOUSHOU_LIST[i]);
            line_str.add(Constants.ZHOUSHOU_LIST[i]);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
//        getCarsList();
        zhoushu = "0";
        newCarsModelArrayList_intent = new ArrayList<NewCarsModel>();//传递数据用的
        UtilsLog.e("onResume()=================");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        instances = null;
        String logStrf = "\n" + "onCreate---onDestroy--调度---上线-------" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
    }

    //获取列表
    private void getCarsList() {
//        if (carsInforModelList != null) {
//            carsInforModelList.clear();
//        }
        String logStrf = "\n" + "-----调度上线--获取列表--getCarsList---" + "\n" + "url::" +
                SharedPreferencesUtils.getIP(instances) + CARS_LIST;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        UtilsLog.e(instances.getClass().getName() + "getCarsList---url==" + SharedPreferencesUtils.getIP(instances) + CARS_LIST);
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + CARS_LIST).tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
                        String logStrf = "\n" + "-----调度上线--获取列表--getCarsList--onSuccess-" + "\n"
                                + "data::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
//                        UtilsLog.e("getDataUsersList-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e(instances.getClass().getName() + "getDataUsersList-newResult==" + newResult);
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            carsInforModelList = new ArrayList<NewCarsModel>();
                            List<NewCarsModel> carsInforModelList2 = new ArrayList<NewCarsModel>();
                            carsInforModelList2 = JsonUtil.stringToArray(newResult,
                                    NewCarsModel[].class);
                            carsInforModelList = new ArrayList(carsInforModelList2);
                            if (carsInforModelList != null && carsInforModelList.size() > 0) {
                                Collections.reverse(carsInforModelList);
                                acDiaoduNewCars.setVisibility(View.VISIBLE);
                                diaoduAdapter = new DiaoDuCarsListAdapter(instances,
                                        carsInforModelList);
                                acDiaoduNewCars.setAdapter(diaoduAdapter);
                            } else {
                                acDiaoduNewCars.setVisibility(View.GONE);
//                                carsInforListAdapter.notifyDataSetChanged();
                                UtilsLog.e(instances.getClass().getName() + "getCarsList-result=22=" + "2222没有数据");
                            }
                        } else {
                            UtilsLog.e(instances.getClass().getName() + "getCarsList-result==" + "没有数据");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        CommonUtils.hideLoadingDialog(instances);
                        String logStrf = "\n" + "-----调度上线--获取列表--getCarsList--onError-" + "\n"
                                + "data::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
                        UtilsLog.e(instances.getClass().getName() + "getCarsList-onError==" + response.body());
                        Toast.makeText(instances, getResources().getString(R.string.services_error), Toast
                                .LENGTH_LONG).show();
                    }
                });
    }

    @OnClick({R.id.ac_diaodu_cars_fab, R.id.ac_diaodu_btn_shangxian
            , R.id.ac_car_details_waijianchedao,
            R.id.ac_diaodu_yincheyuan, R.id.ac_diaodu_digou_user,
            R.id.ac_diaodu_fab})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_diaodu_fab:
                //刷新
                getCarsList();
                break;
            case R.id.ac_diaodu_btn_shangxian:
                //上线
                int maxAccount = 0;
                for (int i = 0; i < DiaoDuCarsListAdapter.sSelected.size(); i++) {
                    if (DiaoDuCarsListAdapter.sSelected.get(i)) {
                        maxAccount = maxAccount + 1;
                    }
                }
                UtilsLog.e("选择的行数：maxAccount==" + maxAccount);
                if (maxAccount > 2) {
                    Toast.makeText(instances, "选择数目不能大于两辆", Toast.LENGTH_LONG).show();
                } else if (maxAccount == 2) {
                    //上线
                    for (int i = 0; i < DiaoDuCarsListAdapter.sSelected.size(); i++) {
                        if (DiaoDuCarsListAdapter.sSelected.get(i)) {
                            newCarsModelArrayList_intent.add(carsInforModelList.get(i));
                        }
                    }
                    if (newCarsModelArrayList_intent != null && newCarsModelArrayList_intent.size() > 0) {
                        boolean status = newCarsModelArrayList_intent.stream().allMatch(m ->
                                m.getNQStatus().equals("1") && m.getUCStatus().equals("1")
                                        && m.getAppearanceStatus().equals("1")
                        );
                        UtilsLog.e("status ==maxAccount == 2===" + status);
                        if (status) {
                            Intent intent = new Intent(instances, NewCarDetailsActivity.class);
                            intent.putExtra("new_car_model", (Serializable) newCarsModelArrayList_intent);
                            intent.putExtra("login_UserID", Login_name);
                            intent.putExtra("login_IDNumber", login_IDNumber);
                            intent.putExtra("zhoushu", zhoushu);
                            startActivity(intent);
                        } else {
                            MessageDialog.show(instances, "提示", "存在未检测完成的项目");
                        }
                    } else {
                        UtilsLog.e("maxAccount == 2---没有数据");
                    }
                } else if (maxAccount == 1) {
                    int index = 0;
                    NewCarsModel model = null;
                    for (int i = 0; i < DiaoDuCarsListAdapter.sSelected.size(); i++) {
                        if (DiaoDuCarsListAdapter.sSelected.get(i)) {
                            index = i;
                        }
                    }
                    model = carsInforModelList.get(index);
                    newCarsModelArrayList_intent.add(model);
                    if (model.getPlateType().equals("15") || (model.getType().substring(0, 1))
                            .equalsIgnoreCase("Q")) {
//                        dialogList(newCarsModelArrayList_intent); // 轴数列表
                        showMyDialog(zhoushu_string, 0,maxAccount);
                    } else {
                        //上线
                        if (newCarsModelArrayList_intent != null && newCarsModelArrayList_intent.size() > 0) {
                            boolean status = newCarsModelArrayList_intent.stream().allMatch(m ->
                                    m.getNQStatus().equals("1") && m.getUCStatus().equals("1")
                                            && m.getAppearanceStatus().equals("1")
                            );
                            UtilsLog.e("status ==maxAccount == 1====" + status);
                            if (status) {
                                Intent intent = new Intent(instances, NewCarDetailsActivity.class);
                                intent.putExtra("new_car_model", (Serializable) newCarsModelArrayList_intent);
                                intent.putExtra("login_UserID", Login_name);
                                intent.putExtra("login_IDNumber", login_IDNumber);
                                intent.putExtra("zhoushu", zhoushu);
                                startActivity(intent);
                            } else {
                                MessageDialog.show(instances, "提示", "存在未检测完成的项目");
                            }

                        }

                    }
                } else if (maxAccount == 0) {
                    Toast.makeText(instances, "请先选择车辆", Toast.LENGTH_LONG).show();
                    UtilsLog.e("列表没有数据");
                }
                break;
            case R.id.ac_car_details_waijianchedao:
                //线号
                if (line_str != null && line_str.size() > 0) {
                    showMyDialog(line_str, 3,0);
                }
                break;
            case R.id.ac_diaodu_yincheyuan:
                //引车员
                if (resultList_string != null && resultList_string.size() > 0) {
                    showMyDialog(resultList_string, 1,0);
                }
                break;
            case R.id.ac_diaodu_digou_user:
                //地沟检验员
                if (digou_string != null && digou_string.size() > 0) {
                    showMyDialog(digou_string, 2,0);
                }
                break;
        }
    }

    void upLine() {
        String logStrf = "\n" + "-----调度上线--右上角按钮点击事件-" + "\n";
        String result = "";
        //上线
        int maxAccount = 0;
        for (int i = 0; i < DiaoDuCarsListAdapter.sSelected.size(); i++) {
            if (DiaoDuCarsListAdapter.sSelected.get(i)) {
                maxAccount = maxAccount + 1;
            }
        }
        UtilsLog.e("选择的行数：maxAccount==" + maxAccount);
        if (maxAccount > 2) {
            Toast.makeText(instances, "选择数目不能大于两辆", Toast.LENGTH_LONG).show();
        } else if (maxAccount == 2) {
            //上线
            for (int i = 0; i < DiaoDuCarsListAdapter.sSelected.size(); i++) {
                if (DiaoDuCarsListAdapter.sSelected.get(i)) {
                    newCarsModelArrayList_intent.add(carsInforModelList.get(i));
                }
            }
            if (newCarsModelArrayList_intent != null && newCarsModelArrayList_intent.size() > 0) {

                boolean status = newCarsModelArrayList_intent.stream().allMatch(m ->
                        (m.getNQStatus().equals("1") || m.getNQStatus().equals("9"))
                                && (m.getUCStatus().equals("1") || m.getUCStatus().equals("9"))
                                && (m.getAppearanceStatus().equals("1") || m.getAppearanceStatus().equals("9"))

                );
                UtilsLog.e("status ==maxAccount == 2===" + status);
                UtilsLog.e("status ==newCarsModelArrayList_intent===" + newCarsModelArrayList_intent.toString());
                result = newCarsModelArrayList_intent.toString() + "\n" + "status==" + status + "\n";
                if (status) {
                    Intent intent = new Intent(instances, NewCarDetailsActivity.class);
                    intent.putExtra("new_car_model", (Serializable) newCarsModelArrayList_intent);
                    intent.putExtra("login_UserID", Login_name);
                    intent.putExtra("login_IDNumber", login_IDNumber);
                    intent.putExtra("zhoushu", zhoushu);
                    intent.putExtra("u_name", acDiaoduYincheyuan.getText().toString().trim());
                    intent.putExtra("u_id", yinche_ID);
                    intent.putExtra("digou_u_name", digou_name);
                    intent.putExtra("digou_u_id", digou_ID);
                    intent.putExtra("line", acCarDetailsWaijianchedao.getText().toString().trim());
                    startActivityForResult(intent, 666);
                } else {
                    MessageDialog.show(instances, "提示", "存在未检测完成的项目").setOkButton(new OnDialogButtonClickListener() {
                        @Override
                        public boolean onClick(BaseDialog baseDialog, View v) {
                            onResume();
                            return false;
                        }
                    });
                }
            } else {
                UtilsLog.e("maxAccount == 2---没有数据");
                result = "maxAccount == 1==newCarsModelArrayList_intent = null " + "\n";
            }
        } else if (maxAccount == 1) {
            int index = 0;
            NewCarsModel model = null;
            for (int i = 0; i < DiaoDuCarsListAdapter.sSelected.size(); i++) {
                if (DiaoDuCarsListAdapter.sSelected.get(i)) {
                    index = i;
                }
            }
            model = carsInforModelList.get(index);
            newCarsModelArrayList_intent.add(model);
            if (model.getPlateType().equals("15") || (model.getType().substring(0, 1))
                    .equalsIgnoreCase("Q")) {
//                        dialogList(newCarsModelArrayList_intent); // 轴数列表
                showMyDialog(zhoushu_string, 0,maxAccount);
            } else {
                //上线
                if (newCarsModelArrayList_intent != null && newCarsModelArrayList_intent.size() > 0) {
//                    boolean status = newCarsModelArrayList_intent.stream().allMatch(m ->
//                            m.getNQStatus().equals("1") && m.getUCStatus().equals("1")
//                                    && m.getAppearanceStatus().equals("1")
//                    );
                    boolean status = newCarsModelArrayList_intent.stream().allMatch(m ->
                            (m.getNQStatus().equals("1") || m.getNQStatus().equals("9"))
                                    && (m.getUCStatus().equals("1") || m.getUCStatus().equals("9"))
                                    && (m.getAppearanceStatus().equals("1") || m.getAppearanceStatus().equals("9"))

                    );
                    UtilsLog.e("status ==maxAccount == 1====" + status);
                    UtilsLog.e("status ==newCarsModelArrayList_intent===" + newCarsModelArrayList_intent.toString());
                    result = newCarsModelArrayList_intent.toString() + "\n" + "status==" + status + "\n";
                    if (status) {
                        Intent intent = new Intent(instances, NewCarDetailsActivity.class);
                        intent.putExtra("new_car_model", (Serializable) newCarsModelArrayList_intent);
                        intent.putExtra("login_UserID", Login_name);
                        intent.putExtra("login_IDNumber", login_IDNumber);
                        intent.putExtra("zhoushu", zhoushu);
                        intent.putExtra("u_name", acDiaoduYincheyuan.getText().toString().trim());
                        intent.putExtra("u_id", yinche_ID);
                        intent.putExtra("digou_u_name", digou_name);
                        intent.putExtra("digou_u_id", digou_ID);
                        intent.putExtra("line", acCarDetailsWaijianchedao.getText().toString().trim());
                        startActivityForResult(intent, 666);
                    } else {
                        MessageDialog.show(instances, "提示", "存在未检测完成的项目").setOkButton(new OnDialogButtonClickListener() {
                            @Override
                            public boolean onClick(BaseDialog baseDialog, View v) {
                                onResume();
                                return false;
                            }
                        });
                    }
                } else {
                    result = "maxAccount == 1==newCarsModelArrayList_intent = null " + "\n";
                }
            }
        } else if (maxAccount == 0) {
            Toast.makeText(instances, "请先选择车辆", Toast.LENGTH_LONG).show();
            UtilsLog.e("列表没有数据");
        }
        logStrf = logStrf + "maxAccount==" + maxAccount + "\n" + "data::" + result;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
    }

    void gotoUpline(int maxAccount) {
        String logStrf = "\n" + "-----调度上线--右上角按钮点击事件-gotoUpline--" + "\n";
        String result = "";
        //上线
        if (newCarsModelArrayList_intent != null && newCarsModelArrayList_intent.size() > 0) {
            boolean status = newCarsModelArrayList_intent.stream().allMatch(m ->
                    (m.getNQStatus().equals("1") || m.getNQStatus().equals("9"))
                            && (m.getUCStatus().equals("1") || m.getUCStatus().equals("9"))
                            && (m.getAppearanceStatus().equals("1") || m.getAppearanceStatus().equals("9"))

            );
            UtilsLog.e("status ==maxAccount == 1====" + status);
            UtilsLog.e("status ==newCarsModelArrayList_intent===" + newCarsModelArrayList_intent.toString());
            result = newCarsModelArrayList_intent.toString() + "\n" + "status==" + status + "\n";
            if (status) {
                Intent intent = new Intent(instances, NewCarDetailsActivity.class);
                intent.putExtra("new_car_model", (Serializable) newCarsModelArrayList_intent);
                intent.putExtra("login_UserID", Login_name);
                intent.putExtra("login_IDNumber", login_IDNumber);
                intent.putExtra("zhoushu", zhoushu);
                intent.putExtra("u_name", acDiaoduYincheyuan.getText().toString().trim());
                intent.putExtra("u_id", yinche_ID);
                intent.putExtra("digou_u_name", digou_name);
                intent.putExtra("digou_u_id", digou_ID);
                intent.putExtra("line", acCarDetailsWaijianchedao.getText().toString().trim());
                startActivityForResult(intent, 666);
            } else {
                MessageDialog.show(instances, "提示", "存在未检测完成的项目").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        onResume();
                        return false;
                    }
                });
            }
        } else {
            result = "maxAccount == 1==newCarsModelArrayList_intent = null " + "\n";
        }
        logStrf = logStrf + "maxAccount==" + maxAccount + "\n" + "data::" + result;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
    }
//
//    private void dialogList(final List<NewCarsModel> model) {
//        final String items[] = Constants.ZHOUSHOU_LIST;
//        AlertDialog.Builder builder = new AlertDialog.Builder(instances, 3);
//        builder.setTitle("请选择轴数");
//        // builder.setMessage("是否确认退出?"); //设置内容
////        builder.setIcon(R.mipmap.ic_launcher);
//        // 设置列表显示，注意设置了列表显示就不要设置builder.setMessage()了，否则列表不起作用。
//        builder.setItems(items, new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                zhoushu = items[which];
//                //上线
//                Intent intent = new Intent(instances, NewCarDetailsActivity.class);
//                intent.putExtra("new_car_model", (Serializable) model);
//                intent.putExtra("login_UserID", Login_name);
//                intent.putExtra("login_IDNumber", login_IDNumber);
//                intent.putExtra("zhoushu", zhoushu);
//                startActivity(intent);
////                dialog.dismiss();
////                Toast.makeText(instances, items[which],
////                        Toast.LENGTH_SHORT).show();
//
//            }
//        });
//        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
////                Toast.makeText(instances, "确定", Toast.LENGTH_SHORT)
////                        .show();
//            }
//        });
//        builder.create().show();
//    }

    //获取用户列表
    private void getDataUsersList() {
        UtilsLog.e("getDataUsersList---url==" + SharedPreferencesUtils.getIP(instances) + GETALLUSERS);
        String logStr = "\n" + "获取用户列表--getDataUsersList----" + "\n" + "URL::" +
                SharedPreferencesUtils.getIP(instances) + GETALLUSERS + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + GETALLUSERS).tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        WaitDialog.show(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataUsersList-newResult==" + newResult);
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            diaoduUserList = JsonUtil.stringToArray(newResult,
                                    UserAccountModel[].class);
                            //0  3  4  6
                            if (diaoduUserList != null && diaoduUserList.size() > 0) {
                                resultList = filterRoleRight(diaoduUserList);
                                resultList_digou = filterRoleRightByDigou(diaoduUserList);

                                if (resultList != null && resultList.size() > 0) {
                                    for (int i = 0; i < resultList.size(); i++) {
                                        resultList_string.add(resultList.get(i).getUserName());
                                    }
                                }

                                if (resultList_digou != null && resultList_digou.size() > 0) {
                                    for (int i = 0; i < resultList_digou.size(); i++) {
                                        digou_string.add(resultList_digou.get(i).getUserName());
                                    }
                                }
                            }
                        } else {
//                            Toast.makeText(instances, getResources().getString(R.string.network_error),
// Toast.LENGTH_LONG).show();
                            UtilsLog.e("getDataUsersList-result==" + "没有数据");
                        }
//                        WaitDialog.dismiss();
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        String logStr = "\n" + "获取用户列表--getDataUsersList----onError" + "\n" + "URL::" +
                                SharedPreferencesUtils.getIP(instances) +
                                GETALLUSERS + "\n" + "result::" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        UtilsLog.e("getDataUsersList-onError==" + response.body());
                        Toast.makeText(instances, "读取人员列表失败，请退出重试", Toast
                                .LENGTH_LONG).show();
                    }
                });
    }

    private List<UserAccountModel> filterRoleRight(List<UserAccountModel> userList) {
        List<UserAccountModel> resultList0 = new ArrayList<>();
        if (userList != null && userList.size() > 0) {
            for (int i = 0; i < userList.size(); i++) {
                if (userList.get(i).getUserRight().contains("0") ||
                        userList.get(i).getUserRight().contains("3")
                        || userList.get(i).getUserRight().contains("4")
                        || userList.get(i).getUserRight().contains("6")) {
                    resultList0.add(userList.get(i));
                }
            }
        }
        for (int i = 0; i < resultList0.size(); i++) {
            UtilsLog.e("过滤后的引车人员列表==" + i + "===" + resultList0.get(i).toString());
        }
        return resultList0;
    }

    private List<UserAccountModel> filterRoleRightByDigou(List<UserAccountModel> userList) {
        List<UserAccountModel> resultList0 = new ArrayList<>();
        if (userList != null && userList.size() > 0) {
            for (int i = 0; i < userList.size(); i++) {
                if (userList.get(i).getUserRight().contains("0") ||
                        userList.get(i).getUserRight().contains("5")) {
                    resultList0.add(userList.get(i));
                }
            }
        }
        for (int i = 0; i < resultList0.size(); i++) {
            UtilsLog.e("过滤后的地沟人员列表==" + i + "===" + resultList0.get(i).toString());
        }
        return resultList0;
    }


    private void showMyDialog(List<String> str, int id,int maxAccount) {
        //maxAccount:是车辆轴数 只在15 Q的条件下用
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                switch (id) {
                    case 0:
                        zhoushu = text;
                        UtilsLog.e("showMyDialog=zhoushu=" + zhoushu);
                        gotoUpline(maxAccount);
                        break;
                    case 1:
                        acDiaoduYincheyuan.setText(text);
                        yinche_name = text;
                        yinche_ID = resultList.get(index).getIDNumber();
                        UtilsLog.e("showMyDialog=yinche_name=" + yinche_name);
                        UtilsLog.e("showMyDialog=yinche_ID=" + yinche_ID);
                        break;
                    case 2:
                        acDiaoduDigouUser.setText(text);
                        digou_name = text.contains("无") ? "" : text;
                        digou_ID = resultList_digou.get(index).getIDNumber();
                        UtilsLog.e("showMyDialog=digou_name=" + digou_name);
                        UtilsLog.e("showMyDialog=digou_ID=" + digou_ID);
                        break;
                    case 3:
                        acCarDetailsWaijianchedao.setText(text);
                        line = text;
                        UtilsLog.e("showMyDialog=line=" + line);
                        break;
                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }


    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UtilsLog.e("11111111111111");
        if (data != null) {
            UtilsLog.e("222222222222");
            switch (requestCode) {
                case 666:
                    UtilsLog.e("33333333333");
                    int flag = data.getIntExtra("flag", 1);
                    if (flag == 1) {
                        String ID = data.getStringExtra("ID");
                        if (carsInforModelList != null && carsInforModelList.size() > 0) {
                            for (int i = carsInforModelList.size() - 1; i >= 0; i--) {
                                if (ID.equals(carsInforModelList.get(i).getID())) {
                                    carsInforModelList.remove(i);
                                }
                            }

//                            for (int i = 0; i < carsInforModelList.size(); i++) {
//                                UtilsLog.e( "ID==" + carsInforModelList.get(i).getID());
//                            }
//                            Collections.reverse(carsInforModelList);
//                            acDiaoduNewCars.setVisibility(View.VISIBLE);
                            diaoduAdapter = new DiaoDuCarsListAdapter(instances,
                                    carsInforModelList);
                            acDiaoduNewCars.setAdapter(diaoduAdapter);
                        } else {
                            acDiaoduNewCars.setVisibility(View.GONE);
                            UtilsLog.e(instances.getClass().getName() + "getCarsList-result=22=" + "2222没有数据");
                        }
                    } else {
                        List<NewCarsModel> upLineList = (List<NewCarsModel>) data.getSerializableExtra("up_line_list");
                        if (upLineList != null && upLineList.size() > 0) {
                            UtilsLog.e("=======" + upLineList.toString());
//                        carsInforModelList.removeAll(upLineList);

                            if (carsInforModelList != null && carsInforModelList.size() > 0) {
                                for (int j = 0; j < upLineList.size(); j++) {
                                    for (int i = carsInforModelList.size() - 1; i >= 0; i--) {
                                        if (upLineList.get(j).getID().equals(carsInforModelList.get(i).getID())) {
                                            carsInforModelList.remove(i);
                                        }
                                    }
                                }

//                                for (int i = 0; i < carsInforModelList.size(); i++) {
//                                    UtilsLog.e(instances.getClass().getName() + "==" + carsInforModelList.get(i).getID());
//                                }
//                            Collections.reverse(carsInforModelList);
//                            acDiaoduNewCars.setVisibility(View.VISIBLE);
                                diaoduAdapter = new DiaoDuCarsListAdapter(instances,
                                        carsInforModelList);
                                acDiaoduNewCars.setAdapter(diaoduAdapter);
                            } else {
                                acDiaoduNewCars.setVisibility(View.GONE);
                                UtilsLog.e(instances.getClass().getName() + "getCarsList-result=22=" + "2222没有数据");
                            }
                        } else {
                            UtilsLog.e(instances.getClass().getName() + "0000000000");
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }

}
